home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
a_utils
/
expanded.lha
/
test_suite
/
testspace.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-19
|
34KB
|
1,413 lines
//
// Linear-Affine-Projective Geometry Package
//
// testspace.C
//
// $Header$
//
// William J.R. Longabaugh
// University of Washington
//
// Test runs for the linear-affine-projective geometry
// package described in William J.R. Longabaugh, "An Expanded
// System for Coordinate-Free Geometric Programming", Master's
// thesis, University of Washington, 1992.
//
// Copyright (c) 1992, William J.R. Longabaugh
// Copying, use and development for non-commercial purposes permitted.
// All rights for commercial use reserved.
// This software is unsupported and without warranty; it is
// provided "as is".
//
// ***********************************************************************
#include "Lap.h"
#include <math.h>
extern void test1(void);
extern void test2(void);
extern void test3(void);
extern void test4(void);
extern void test5(void);
extern void test6(void);
extern void test7(void);
extern void test8(void);
extern void test9(void);
extern void test10(void);
extern void test11(void);
extern void test12(void);
extern void test13(void);
extern void test14(void);
extern void test15(void);
extern void test16(void);
extern void test17(void);
extern void test18(void);
extern void report(AVector res);
extern void truth(Boolean res, Boolean expect);
extern void probe(Space root);
// ***********************************************************************
int main(void)
{
test1();
test2();
test3();
test4();
test5();
test6();
test7();
test8();
test9();
test10();
test11();
test12();
test13();
test14();
test15();
test16();
test17();
test18();
return (0);
}
// ***********************************************************************
// Test manual stitching of spaces using arbitrary maps
// ***********************************************************************
// LinkLAHaveLP
void test1(void)
{
cout << "ENTERING TEST1\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", 2);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
Vector v1(bas, ScalarList(2.4, 5.6, 1.2));
Vector v2(bas, ScalarList(1.0, 6.2, 8.9));
Vector v3(bas, ScalarList(7.8, 3.3, 4.6));
Vector v4(bas, ScalarList(3.4, 8.9, 0.9));
VectorEC veq1 = v1;
VectorEC veq2 = v2;
VectorEC veq3 = v3;
VectorEC veq4 = v4;
ASubSet mas("my asubset", v, GeObList(v1, v2, v3));
APoint p1(fra, ScalarList(4.5, 9.2, 1.0));
APoint p2(fra, ScalarList(5.7, 1.3, 1.0));
APoint p3(fra, ScalarList(7.7, 8.2, 1.0));
Simplex sp("test simplex", a, GeObList(p1, p2, p3));
PPoint pp1(hfr, ScalarList(2.4, 4.5, 7.8));
PPoint pp2(hfr, ScalarList(7.2, 3.9, 4.1));
PPoint pp3(hfr, ScalarList(5.7, 2.3, 9.1));
PPoint pp4(hfr, ScalarList(9.6, 8.4, 11.9));
PPoint pp5(hfr, ScalarList(8.1, 6.8, 16.9));
ASubSet masp("my asubset in p", p, pp1, GeObList(pp2, pp3));
ProjectiveMap pm1(hfr, v.FullProjSet(), GeObList(veq1, veq2, veq3, veq4));
AffineMap am1(sp, mas, GeObList(v1, v2, v3));
AffineMap am2(sp, masp, GeObList(pp1, pp4, pp5));
p.SetSpace(v, pm1);
a.SetSpace(v, am1);
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
void report(AVector res)
{
if (res.IsZeroVector()) {
cout << "Success\n";
} else {
cout << "Failure\n";
}
}
// ***********************************************************************
//
// Probe the six-space set entries of all spaces in a six-space set
//
void probe(Space root)
{
char buf[200];
for (int i = 0; i < (int)NO_RELATION; i++) {
SRelOut(cout, (SRel)i);
cout << ":\n";
for (int j = 0; j < (int)NO_RELATION; j++) {
Space hold1 = root.GetSpace((SRel) j);
Space hold2 = hold1.GetSpace((SRel) i);
hold2.Name(buf);
cout << buf << " Dimension: " << hold2.Dim() << "\n";
}
}
}
// ***********************************************************************
// LinkAPHaveLP
void test2(void)
{
cout << "ENTERING TEST2\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", 2);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
Vector v1(bas, ScalarList(2.4, 5.6, 1.2));
Vector v2(bas, ScalarList(1.0, 6.2, 8.9));
Vector v3(bas, ScalarList(7.8, 3.3, 4.6));
Vector v4(bas, ScalarList(3.4, 8.9, 0.9));
VectorEC veq1 = v1;
VectorEC veq2 = v2;
VectorEC veq3 = v3;
VectorEC veq4 = v4;
ASubSet mas("my asubset", v, GeObList(v1, v2, v3));
APoint p1(fra, ScalarList(4.5, 9.2, 1.0));
APoint p2(fra, ScalarList(5.7, 1.3, 1.0));
APoint p3(fra, ScalarList(7.7, 8.2, 1.0));
Simplex sp("test simplex", a, GeObList(p1, p2, p3));
PPoint pp1(hfr, ScalarList(2.4, 4.5, 7.8));
PPoint pp2(hfr, ScalarList(7.2, 3.9, 4.1));
PPoint pp3(hfr, ScalarList(5.7, 2.3, 9.1));
PPoint pp4(hfr, ScalarList(9.6, 8.4, 11.9));
PPoint pp5(hfr, ScalarList(8.1, 6.8, 16.9));
ASubSet masp("my asubset in p", p, pp1, GeObList(pp2, pp3));
ProjectiveMap pm1(hfr, v.FullProjSet(), GeObList(veq1, veq2, veq3, veq4));
AffineMap am1(sp, mas, GeObList(v1, v2, v3));
AffineMap am2(sp, masp, GeObList(pp1, pp4, pp5));
p.SetSpace(v, pm1);
a.SetSpace(p, am2);
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkLAHaveAP
void test3(void)
{
cout << "ENTERING TEST3\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", 2);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
Vector v1(bas, ScalarList(2.4, 5.6, 1.2));
Vector v2(bas, ScalarList(1.0, 6.2, 8.9));
Vector v3(bas, ScalarList(7.8, 3.3, 4.6));
Vector v4(bas, ScalarList(3.4, 8.9, 0.9));
VectorEC veq1 = v1;
VectorEC veq2 = v2;
VectorEC veq3 = v3;
VectorEC veq4 = v4;
ASubSet mas("my asubset", v, GeObList(v1, v2, v3));
APoint p1(fra, ScalarList(4.5, 9.2, 1.0));
APoint p2(fra, ScalarList(5.7, 1.3, 1.0));
APoint p3(fra, ScalarList(7.7, 8.2, 1.0));
Simplex sp("test simplex", a, GeObList(p1, p2, p3));
PPoint pp1(hfr, ScalarList(2.4, 4.5, 7.8));
PPoint pp2(hfr, ScalarList(7.2, 3.9, 4.1));
PPoint pp3(hfr, ScalarList(5.7, 2.3, 9.1));
PPoint pp4(hfr, ScalarList(9.6, 8.4, 11.9));
PPoint pp5(hfr, ScalarList(8.1, 6.8, 16.9));
ASubSet masp("my asubset in p", p, pp1, GeObList(pp2, pp3));
ProjectiveMap pm1(hfr, v.FullProjSet(), GeObList(veq1, veq2, veq3, veq4));
AffineMap am1(sp, mas, GeObList(v1, v2, v3));
AffineMap am2(sp, masp, GeObList(pp1, pp4, pp5));
a.SetSpace(p, am2);
a.SetSpace(v, am1);
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkAPHaveLA
void test4(void)
{
cout << "ENTERING TEST4\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", 2);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
Vector v1(bas, ScalarList(2.4, 5.6, 1.2));
Vector v2(bas, ScalarList(1.0, 6.2, 8.9));
Vector v3(bas, ScalarList(7.8, 3.3, 4.6));
Vector v4(bas, ScalarList(3.4, 8.9, 0.9));
VectorEC veq1 = v1;
VectorEC veq2 = v2;
VectorEC veq3 = v3;
VectorEC veq4 = v4;
ASubSet mas("my asubset", v, GeObList(v1, v2, v3));
APoint p1(fra, ScalarList(4.5, 9.2, 1.0));
APoint p2(fra, ScalarList(5.7, 1.3, 1.0));
APoint p3(fra, ScalarList(7.7, 8.2, 1.0));
Simplex sp("test simplex", a, GeObList(p1, p2, p3));
PPoint pp1(hfr, ScalarList(2.4, 4.5, 7.8));
PPoint pp2(hfr, ScalarList(7.2, 3.9, 4.1));
PPoint pp3(hfr, ScalarList(5.7, 2.3, 9.1));
PPoint pp4(hfr, ScalarList(9.6, 8.4, 11.9));
PPoint pp5(hfr, ScalarList(8.1, 6.8, 16.9));
ASubSet masp("my asubset in p", p, pp1, GeObList(pp2, pp3));
ProjectiveMap pm1(hfr, v.FullProjSet(), GeObList(veq1, veq2, veq3, veq4));
AffineMap am1(sp, mas, GeObList(v1, v2, v3));
AffineMap am2(sp, masp, GeObList(pp1, pp4, pp5));
a.SetSpace(v, am1);
a.SetSpace(p, am2);
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkLPHaveLA
void test5(void)
{
cout << "ENTERING TEST5\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", 2);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
Vector v1(bas, ScalarList(2.4, 5.6, 1.2));
Vector v2(bas, ScalarList(1.0, 6.2, 8.9));
Vector v3(bas, ScalarList(7.8, 3.3, 4.6));
Vector v4(bas, ScalarList(3.4, 8.9, 0.9));
VectorEC veq1 = v1;
VectorEC veq2 = v2;
VectorEC veq3 = v3;
VectorEC veq4 = v4;
ASubSet mas("my asubset", v, GeObList(v1, v2, v3));
APoint p1(fra, ScalarList(4.5, 9.2, 1.0));
APoint p2(fra, ScalarList(5.7, 1.3, 1.0));
APoint p3(fra, ScalarList(7.7, 8.2, 1.0));
Simplex sp("test simplex", a, GeObList(p1, p2, p3));
PPoint pp1(hfr, ScalarList(2.4, 4.5, 7.8));
PPoint pp2(hfr, ScalarList(7.2, 3.9, 4.1));
PPoint pp3(hfr, ScalarList(5.7, 2.3, 9.1));
PPoint pp4(hfr, ScalarList(9.6, 8.4, 11.9));
PPoint pp5(hfr, ScalarList(8.1, 6.8, 16.9));
ASubSet masp("my asubset in p", p, pp1, GeObList(pp2, pp3));
ProjectiveMap pm1(hfr, v.FullProjSet(), GeObList(veq1, veq2, veq3, veq4));
AffineMap am1(sp, mas, GeObList(v1, v2, v3));
AffineMap am2(sp, masp, GeObList(pp1, pp4, pp5));
a.SetSpace(v, am1);
p.SetSpace(v, pm1);
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkLPHaveAP
void test6(void)
{
cout << "ENTERING TEST6\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", 2);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
Vector v1(bas, ScalarList(2.4, 5.6, 1.2));
Vector v2(bas, ScalarList(1.0, 6.2, 8.9));
Vector v3(bas, ScalarList(7.8, 3.3, 4.6));
Vector v4(bas, ScalarList(3.4, 8.9, 0.9));
VectorEC veq1 = v1;
VectorEC veq2 = v2;
VectorEC veq3 = v3;
VectorEC veq4 = v4;
ASubSet mas("my asubset", v, GeObList(v1, v2, v3));
APoint p1(fra, ScalarList(4.5, 9.2, 1.0));
APoint p2(fra, ScalarList(5.7, 1.3, 1.0));
APoint p3(fra, ScalarList(7.7, 8.2, 1.0));
Simplex sp("test simplex", a, GeObList(p1, p2, p3));
PPoint pp1(hfr, ScalarList(2.4, 4.5, 7.8));
PPoint pp2(hfr, ScalarList(7.2, 3.9, 4.1));
PPoint pp3(hfr, ScalarList(5.7, 2.3, 9.1));
PPoint pp4(hfr, ScalarList(9.6, 8.4, 11.9));
PPoint pp5(hfr, ScalarList(8.1, 6.8, 16.9));
ASubSet masp("my asubset in p", p, pp1, GeObList(pp2, pp3));
ProjectiveMap pm1(hfr, v.FullProjSet(), GeObList(veq1, veq2, veq3, veq4));
AffineMap am1(sp, mas, GeObList(v1, v2, v3));
AffineMap am2(sp, masp, GeObList(pp1, pp4, pp5));
a.SetSpace(p, am2);
p.SetSpace(v, pm1);
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkLAHaveLP
void test7(void)
{
cout << "ENTERING TEST7\n";
VSpace v("Test vector space", 3, TRUE);
PSpace p("Test projective space", v);
ASpace a("Test affine space", TRUE, v);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkAPHaveLP
void test8(void)
{
cout << "ENTERING TEST8\n";
PSpace p("Test projective space", 2);
VSpace v("Test vector space", TRUE, p);
ASpace a("Test affine space", TRUE, p);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkLAHaveAP
void test9(void)
{
cout << "ENTERING TEST9\n";
PSpace p("Test projective space", 2);
ASpace a("Test affine space", TRUE, p);
VSpace v("Test vector space", TRUE, a);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkAPHaveLA
void test10(void)
{
cout << "ENTERING TEST10\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", TRUE, v);
PSpace p("Test projective space", a);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkLPHaveLA
void test11(void)
{
cout << "ENTERING TEST11\n";
ASpace a("Test affine space", 2, TRUE);
VSpace v("Test vector space", TRUE, a);
PSpace p("Test projective space", v);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
// LinkLPHaveAP
void test12(void)
{
cout << "ENTERING TEST12\n";
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", a);
VSpace v("Test vector space", TRUE, p);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
// Send a point around the map loop...
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = orig;
veqt = 2 * vt;
ppt = veqt;
apt = ppt;
report(orig - apt);
vt = orig;
ppt = vt;
apt = ppt;
report(orig - apt);
ppt = orig;
vt = ppt;
apt = vt;
report(orig - apt);
vt = avto;
avt = vt;
report(avto - avt);
probe(a);
}
// ***********************************************************************
void truth(Boolean res, Boolean expect)
{
if (res == expect) {
cout << "Success\n";
} else {
cout << "Failure\n";
}
}
// ***********************************************************************
// Test for space gets, relations, space tests, native types, duals
void test13(void)
{
//
// Manually build a set:
//
cout << "ENTERING TEST13\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", 2);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
Vector v1(bas, ScalarList(2.4, 5.6, 1.2));
Vector v2(bas, ScalarList(1.0, 6.2, 8.9));
Vector v3(bas, ScalarList(7.8, 3.3, 4.6));
Vector v4(bas, ScalarList(3.4, 8.9, 0.9));
VectorEC veq1 = v1;
VectorEC veq2 = v2;
VectorEC veq3 = v3;
VectorEC veq4 = v4;
ASubSet mas("my asubset", v, GeObList(v1, v2, v3));
APoint p1(fra, ScalarList(4.5, 9.2, 1.0));
APoint p2(fra, ScalarList(5.7, 1.3, 1.0));
APoint p3(fra, ScalarList(7.7, 8.2, 1.0));
Simplex sp("test simplex", a, GeObList(p1, p2, p3));
PPoint pp1(hfr, ScalarList(2.4, 4.5, 7.8));
PPoint pp2(hfr, ScalarList(7.2, 3.9, 4.1));
PPoint pp3(hfr, ScalarList(5.7, 2.3, 9.1));
PPoint pp4(hfr, ScalarList(9.6, 8.4, 11.9));
PPoint pp5(hfr, ScalarList(8.1, 6.8, 16.9));
ASubSet masp("my asubset in p", p, pp1, GeObList(pp2, pp3));
ProjectiveMap pm1(hfr, v.FullProjSet(), GeObList(veq1, veq2, veq3, veq4));
AffineMap am1(sp, mas, GeObList(v1, v2, v3));
AffineMap am2(sp, masp, GeObList(pp1, pp4, pp5));
p.SetSpace(v, pm1);
a.SetSpace(v, am1);
// The following should all be as indicated:
truth(a.HasSpace(TANGENT), FALSE);
truth(v.HasSpace(TANG_DUAL), FALSE);
truth(p.HasSpace(LIN_DUAL), FALSE);
truth(p.HasSpace(LINEARIZATION), TRUE);
truth(v.HasSpace(AFFINE), TRUE);
truth(a.HasSpace(PROJECT_COMP), TRUE);
// Get some spaces, test equal and not equal:
Space td = p.GetSpace(TANG_DUAL);
Space ld = td.GetSpace(LIN_DUAL);
Space t = ld.GetSpace(TANGENT);
Space s1 = td.GetSpace(AFFINE);
Space s2 = ld.GetSpace(PROJECT_COMP);
Space s3 = t.GetSpace(LINEARIZATION);
Space td2 = ld.GetSpace(TANG_DUAL);
truth((s1 == a), TRUE);
truth((s2 == p), TRUE);
truth((s3 == v), TRUE);
truth((td == td2), TRUE);
truth((td != t), TRUE);
truth((a != s1), FALSE);
truth((a.GetSpace(LINEARIZATION) == v), TRUE);
truth((p.GetSpace(TANGENT) == t), TRUE);
truth((v.GetSpace(TANG_DUAL) == td), TRUE);
truth((td.GetSpace(AFFINE) == a), TRUE);
truth((ld.GetSpace(PROJECT_COMP) == p), TRUE);
truth((t.GetSpace(LIN_DUAL) == ld), TRUE);
// Check SRel functions:
truth((a.ThisSpaceIs() == AFFINE), TRUE);
truth((p.ThisSpaceIs() == PROJECT_COMP), TRUE);
truth((v.ThisSpaceIs() == LINEARIZATION), TRUE);
truth((td.ThisSpaceIs() == TANG_DUAL), TRUE);
truth((ld.ThisSpaceIs() == LIN_DUAL), TRUE);
truth((t.ThisSpaceIs() == TANGENT), TRUE);
VSpace odd("Odd space", 2, FALSE);
truth((a.SpaceRelation(a) == SAME_SPACE), TRUE);
truth((p.SpaceRelation(odd) == NO_RELATION), TRUE);
truth((v.SpaceRelation(a) == AFFINE), TRUE);
truth((td.SpaceRelation(p) == PROJECT_COMP), TRUE);
truth((ld.SpaceRelation(td) == TANG_DUAL), TRUE);
truth((t.SpaceRelation(v) == LINEARIZATION), TRUE);
// Check native type functions:
truth((a.NativeType() == AFF_POINT), TRUE);
truth((p.NativeType() == PROJ_POINT), TRUE);
truth((v.NativeType() == VECTOR), TRUE);
truth((td.NativeType() == VECTOR), TRUE);
truth((ld.NativeType() == VECTOR), TRUE);
truth((t.NativeType() == AFF_VECTOR), TRUE);
// Check dual functions:
truth((v.Dual() == ld), TRUE);
truth((td.Dual() == t), TRUE);
truth((ld.Dual() == v), TRUE);
truth((t.Dual() == td), TRUE);
}
// ***********************************************************************
// Test for points at infinity, standard subsets:
void test14(void)
{
int i;
//
// Manually build a set:
//
cout << "ENTERING TEST14\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", 2);
//
// Bare projective spaces do not have points at infinity:
//
GeObList pts = p.PtsAtInfinity();
truth((pts.Length() == 0), TRUE);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
Simplex simp = a.StdSimplex();
Vector v1(bas, ScalarList(2.4, 5.6, 1.2));
Vector v2(bas, ScalarList(1.0, 6.2, 8.9));
Vector v3(bas, ScalarList(7.8, 3.3, 4.6));
Vector v4(bas, ScalarList(3.4, 8.9, 0.9));
VectorEC veq1 = v1;
VectorEC veq2 = v2;
VectorEC veq3 = v3;
VectorEC veq4 = v4;
ASubSet mas("my asubset", v, GeObList(v1, v2, v3));
APoint p1(fra, ScalarList(4.5, 9.2, 1.0));
APoint p2(fra, ScalarList(5.7, 1.3, 1.0));
APoint p3(fra, ScalarList(7.7, 8.2, 1.0));
Simplex sp("test simplex", a, GeObList(p1, p2, p3));
PPoint pp1(hfr, ScalarList(2.4, 4.5, 7.8));
PPoint pp2(hfr, ScalarList(7.2, 3.9, 4.1));
PPoint pp3(hfr, ScalarList(5.7, 2.3, 9.1));
PPoint pp4(hfr, ScalarList(9.6, 8.4, 11.9));
PPoint pp5(hfr, ScalarList(8.1, 6.8, 16.9));
ASubSet masp("my asubset in p", p, pp1, GeObList(pp2, pp3));
ProjectiveMap pm1(hfr, v.FullProjSet(), GeObList(veq1, veq2, veq3, veq4));
AffineMap am1(sp, mas, GeObList(v1, v2, v3));
AffineMap am2(sp, masp, GeObList(pp1, pp4, pp5));
p.SetSpace(v, pm1);
a.SetSpace(v, am1);
//
// Get the points at infinity. Check to make sure that they are not
// in the standard affine subset of the space:
//
pts = p.PtsAtInfinity();
int len = pts.Length();
ASubSet stda = p.StdAffineSubset();
for (i = 0; i < len; i++) {
truth(stda.IsIn(pts[i]), FALSE);
}
//
// Everybody in a basis had better be in the full set:
//
len = v.Dim();
VSubSet vfull = v.FullSet();
for (i = 0; i < len; i++) {
truth(vfull.IsIn(bas[i]), TRUE);
}
len = a.Dim() + 1;
ASubSet afull = a.FullSet();
for (i = 0; i < len; i++) {
truth(afull.IsIn(simp[i]), TRUE);
}
len = p.Dim() + 2;
PSubSet pfull = p.FullSet();
for (i = 0; i < len; i++) {
truth(pfull.IsIn(hfr[i]), TRUE);
}
//
// All VectorEC derived from a basis had better be in the
// full projective set:
//
len = v.Dim();
PSubSet vfullpr = v.FullProjSet();
for (i = 0; i < len; i++) {
truth(vfullpr.IsIn(VectorEC(bas[i])), TRUE);
}
VSpace t = a.GetSpace(TANGENT);
VBasis tbas = t.StdBasis();
len = t.Dim();
PSubSet tfullpr = t.FullProjSet();
for (i = 0; i < len; i++) {
truth(tfullpr.IsIn(AVectorEC(tbas[i])), TRUE);
}
len = p.Dim() + 2;
PSubSet pfullpr = p.FullProjSet();
for (i = 0; i < len; i++) {
truth(pfullpr.IsIn(hfr[i]), TRUE);
}
//
// Points in affine space, when cast, had better be in the
// std affine subset. Points and infinity (checked above)
// and cast affine vectors are not:
//
len = a.Dim() + 1;
ASubSet vsas = v.StdAffineSubset();
for (i = 0; i < len; i++) {
truth(vsas.IsIn(Vector(simp[i])), TRUE);
}
for (i = 0; i < t.Dim(); i++) {
truth(vsas.IsIn(Vector(tbas[i])), FALSE);
}
ASubSet asas = a.StdAffineSubset();
for (i = 0; i < len; i++) {
truth(asas.IsIn(simp[i]), TRUE);
}
ASubSet psas = p.StdAffineSubset();
for (i = 0; i < len; i++) {
truth(psas.IsIn(PPoint(simp[i])), TRUE);
}
}
// ***********************************************************************
// Test for standard maps. This has already been given a pretty
// extensive workout during tests of geobs.
void test15(void)
{
//
// Manually build a set:
//
cout << "ENTERING TEST15\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", 2);
VBasis bas = v.StdBasis();
Frame fra = a.StdBasis();
HFrame hfr = p.StdBasis();
Simplex simp = a.StdSimplex();
Vector v1(bas, ScalarList(2.4, 5.6, 1.2));
Vector v2(bas, ScalarList(1.0, 6.2, 8.9));
Vector v3(bas, ScalarList(7.8, 3.3, 4.6));
Vector v4(bas, ScalarList(3.4, 8.9, 0.9));
VectorEC veq1 = v1;
VectorEC veq2 = v2;
VectorEC veq3 = v3;
VectorEC veq4 = v4;
ASubSet mas("my asubset", v, GeObList(v1, v2, v3));
APoint p1(fra, ScalarList(4.5, 9.2, 1.0));
APoint p2(fra, ScalarList(5.7, 1.3, 1.0));
APoint p3(fra, ScalarList(7.7, 8.2, 1.0));
Simplex sp("test simplex", a, GeObList(p1, p2, p3));
PPoint pp1(hfr, ScalarList(2.4, 4.5, 7.8));
PPoint pp2(hfr, ScalarList(7.2, 3.9, 4.1));
PPoint pp3(hfr, ScalarList(5.7, 2.3, 9.1));
PPoint pp4(hfr, ScalarList(9.6, 8.4, 11.9));
PPoint pp5(hfr, ScalarList(8.1, 6.8, 16.9));
ASubSet masp("my asubset in p", p, pp1, GeObList(pp2, pp3));
ProjectiveMap pm1(hfr, v.FullProjSet(), GeObList(veq1, veq2, veq3, veq4));
AffineMap am1(sp, mas, GeObList(v1, v2, v3));
AffineMap am2(sp, masp, GeObList(pp1, pp4, pp5));
p.SetSpace(v, pm1);
a.SetSpace(v, am1);
//
// Get a whole bunch of standard maps
//
LinearMap vtot = v.LinearMapTo(TANGENT);
VSpace t = v.GetSpace(TANGENT);
LinearMap ttov = t.LinearMapTo(LINEARIZATION);
AffineMap ptov = p.AffineMapTo(LINEARIZATION);
AffineMap vtop = v.AffineMapTo(PROJECT_COMP);
AffineMap atov = a.AffineMapTo(LINEARIZATION);
AffineMap vtoa = v.AffineMapTo(AFFINE);
AffineMap atop = a.AffineMapTo(PROJECT_COMP);
AffineMap ptoa = p.AffineMapTo(AFFINE);
ProjectiveMap ptovp = p.ProjectiveMapTo(LINEARIZATION);
ProjectiveMap vtopp = v.ProjectiveMapTo(PROJECT_COMP);
Vector vt;
VectorEC veqt;
PPoint ppt;
AVector avt;
APoint apt;
AVector avto(fra, ScalarList(2.4, 6.7, 0.0));
APoint orig(fra, ScalarList(4.0, 2.3, 1.0));
vt = atov(orig);
// g++ 1.37.1 has problems with the following chained virtual function:
// veqt = (2 * vt).MapTo(VEC_EC);
// so:
Vector temp = 2 * vt;
veqt = temp.MapTo(VEC_EC);
ppt = vtopp(veqt);
apt = ptoa(ppt);
report(orig - apt);
vt = atov(orig);
ppt = vtop(vt);
apt = ptoa(ppt);
report(orig - apt);
ppt = atop(orig);
vt = ptov(ppt);
apt = vtoa(vt);
report(orig - apt);
vt = ttov(avto);
avt = vtot(vt);
report(avto - avt);
}
// ***********************************************************************
// Test for Euclidean stuff:
void test16(void)
{
cout << "ENTERING TEST16\n";
VSpace vs2 = VSpace("vs2", 2, TRUE);
VSpace vs3 = VSpace("vs3", 3, TRUE);
VSpace vs4 = VSpace("vs4", 4, TRUE);
ASpace as2 = ASpace("as2", 2, TRUE);
ASpace as3 = ASpace("as3", 3, TRUE);
ASpace as4 = ASpace("as4", 4, TRUE);
VSpace t2 = as2.GetSpace(TANGENT);
VSpace t3 = as3.GetSpace(TANGENT);
VSpace t4 = as4.GetSpace(TANGENT);
truth(vs2.IsEuclidean(), TRUE);
truth(vs3.IsEuclidean(), TRUE);
truth(vs4.IsEuclidean(), TRUE);
truth(as2.IsEuclidean(), TRUE);
truth(as3.IsEuclidean(), TRUE);
truth(as4.IsEuclidean(), TRUE);
truth(t2.IsEuclidean(), TRUE);
truth(t3.IsEuclidean(), TRUE);
truth(t4.IsEuclidean(), TRUE);
MLM vs2ip = vs2.InnerProduct();
MLM vs3ip = vs3.InnerProduct();
MLM vs4ip = vs4.InnerProduct();
MLM t2ip = t2.InnerProduct();
MLM t3ip = t3.InnerProduct();
MLM t4ip = t4.InnerProduct();
MLM vs2cp = vs2.CrossProduct();
MLM vs3cp = vs3.CrossProduct();
MLM vs4cp = vs4.CrossProduct();
MLM t2cp = t2.CrossProduct();
MLM t3cp = t3.CrossProduct();
MLM t4cp = t4.CrossProduct();
//
// Test the functions:
//
VBasis bas2 = vs2.StdBasis();
VBasis bas3 = vs3.StdBasis();
VBasis bas4 = vs4.StdBasis();
Vector v2a(bas2, ScalarList(2.4, 1.2));
Vector v2b(bas2, ScalarList(6.2, 8.9));
Vector v3a(bas3, ScalarList(2.4, 5.6, 1.2));
Vector v3b(bas3, ScalarList(1.0, 6.2, 8.9));
Vector v4a(bas4, ScalarList(2.4, 5.6, 1.2, 3.6));
Vector v4b(bas4, ScalarList(7.8, 3.3, 4.6, 7.2));
Vector v4c(bas4, ScalarList(3.4, 8.9, 0.9, 1.5));
Scalar res = vs2ip(GeObList(v2a, v2b)).ToScalar();
cout << res << "\n";
res = vs3ip(GeObList(v3a, v3b)).ToScalar();
cout << res << "\n";
res = vs4ip(GeObList(v4a, v4b)).ToScalar();
cout << res << "\n";
Vector resv = vs2cp(GeObList(v2a));
cout << resv << "\n";
res = vs2ip(GeObList(v2a, resv)).ToScalar();;
cout << res << "\n";
resv = vs2cp(GeObList(bas2[0]));
cout << resv << "\n";
resv = vs3cp(GeObList(v3a, v3b));
cout << resv << "\n";
res = vs3ip(GeObList(v3a, resv)).ToScalar();
cout << res << "\n";
res = vs3ip(GeObList(v3b, resv)).ToScalar();
cout << res << "\n";
resv = vs3cp(GeObList(bas3[0], bas3[1]));
cout << resv << "\n";
resv = vs4cp(GeObList(v4a, v4b, v4c));
cout << resv << "\n";
res = vs4ip(GeObList(v4a, resv)).ToScalar();
cout << res << "\n";
res = vs4ip(GeObList(v4b, resv)).ToScalar();
cout << res << "\n";
res = vs4ip(GeObList(v4c, resv)).ToScalar();
cout << res << "\n";
resv = vs4cp(GeObList(v4a, v4c, v4b));
cout << resv << "\n";
resv = vs4cp(GeObList(v4c, v4a, v4b));
cout << resv << "\n";
resv = vs4cp(GeObList(bas4[0], bas4[1], bas4[2]));
cout << resv << "\n";
}
// ***********************************************************************
// Test automatic space creation
void test17(void)
{
cout << "ENTERING TEST17\n";
VSpace v = VSpace("test vspace", 3, TRUE);
PSpace p = v.GetSpace(PROJECT_COMP);
VSpace td = p.GetSpace(TANG_DUAL);
ASpace a = td.GetSpace(AFFINE);
VSpace t = p.GetSpace(TANGENT);
VSpace vd = p.GetSpace(LIN_DUAL);
probe(a);
}
// ***********************************************************************
// Test space lists and cartesian product space creation
void test18(void)
{
cout << "ENTERING TEST18\n";
ASpace a = ASpace("aspace", 1, TRUE);
ASpace b = ASpace("bspace", 2, FALSE);
ASpace c = ASpace("cspace", 2, TRUE);
ASpace d = ASpace("dspace", 3, TRUE);
ASpace e = ASpace("espace", 1, TRUE);
SpaceList foo1(a, b, c);
SpaceList foo2(2);
SpaceList foo;
foo2[0] = d;
foo2[1] = e;
foo = foo1 + foo2;
VSpace dt = d.GetSpace(TANGENT);
VSpace bt = b.GetSpace(TANGENT);
truth((a.CPSpaceSize() == 1), TRUE);
truth((a[0] == a), TRUE);
ASpace cptest("cptest", foo, FALSE);
VSpace cpt = cptest.GetSpace(TANGENT);
SpaceList foo3 = SpaceList(cptest) + foo2;
ASpace cptest2("cptest2", foo3, FALSE);
truth((cptest.Dim() == 9), TRUE);
truth((cptest.CPSpaceSize() == 5), TRUE);
truth((cptest[0] == a), TRUE);
truth((cptest[1] == b), TRUE);
truth((cptest[2] == c), TRUE);
truth((cptest[3] == d), TRUE);
truth((cptest[4] == e), TRUE);
truth((cpt[3] == dt), TRUE);
truth((cpt[1] == bt), TRUE);
truth((cptest2.Dim() == 13), TRUE);
truth((cptest2[0] == a), TRUE);
truth((cptest2[1] == b), TRUE);
truth((cptest2[2] == c), TRUE);
truth((cptest2[3] == d), TRUE);
truth((cptest2[4] == e), TRUE);
truth((cptest2[5] == d), TRUE);
truth((cptest2[6] == e), TRUE);
//
// The following will not work with g++ 1.37.1 due to problems
// with premature destructor calls (which shows up when matrices
// of size > 4 use the heap):
//
Simplex stdcp = cptest.StdSimplex();
APoint ss3 = stdcp[3];
cout << ss3;
VSpace av("av", 1, TRUE);
VSpace bv("bv", 2, FALSE);
VSpace cv("cv", 2, TRUE);
VSpace cvd = cv.Dual();
SpaceList foov(av, bv, cv);
VSpace cpv("cpv", foov, FALSE);
VSpace cpvd = cpv.Dual();
truth((cpv.Dim() == 5), TRUE);
truth((cpv.CPSpaceSize() == 3), TRUE);
truth((cpv[0] == av), TRUE);
truth((cpv[1] == bv), TRUE);
truth((cpv[2] == cv), TRUE);
truth((cpvd[2] == cvd), TRUE);
//
// Expect the same g++ problem as above:
//
VBasis stbcp = cpv.StdBasis();
Vector sb2 = stbcp[2];
cout << sb2;
}